<?php

namespace app\controller\api\controller;

use app\service\WorkspaceService;
use app\support\ResponseHelper;
use Carbon\Carbon;
use DI\Attribute\Inject;
use Shayvmo\WebmanAnnotations\Annotations\GetMapping;
use Shayvmo\WebmanAnnotations\Annotations\RestController;
use support\Log;
use Webman\Http\Response;

/**
 * 工作台相关接口
 */
#[RestController("/api/workspace")]
class WorkSpaceController
{
    #[Inject]
    protected WorkspaceService $workspaceService;

    /**
     * 工作台今日数据查询
     * @return Response
     */
    #[GetMapping("/businessData")]
    public function businessData(): Response
    {
        // 获得当天的开始时间
        $begin = Carbon::now()->startOfDay()->format('Y-m-d H:i:s');
        // 获得当天的结束时间
        $end = Carbon::now()->endOfDay()->format('Y-m-d H:i:s');
        
        Log::info("工作台今日数据查询：{$begin} 至 {$end}");
        
        $businessDataVO = $this->workspaceService->getBusinessData($begin, $end);
        return ResponseHelper::successJson($businessDataVO->toArray());
    }

    /**
     * 查询订单管理数据
     * @return Response
     */
    #[GetMapping("/overviewOrders")]
    public function orderOverView(): Response
    {
        Log::info("查询订单管理数据");
        
        $orderOverViewVO = $this->workspaceService->getOrderOverView();
        return ResponseHelper::successJson($orderOverViewVO->toArray());
    }

    /**
     * 查询菜品总览
     * @return Response
     */
    #[GetMapping("/overviewDishes")]
    public function dishOverView(): Response
    {
        Log::info("查询菜品总览");
        
        $dishOverViewVO = $this->workspaceService->getDishOverView();
        return ResponseHelper::successJson($dishOverViewVO->toArray());
    }

    /**
     * 查询套餐总览
     * @return Response
     */
    #[GetMapping("/overviewSetmeals")]
    public function setmealOverView(): Response
    {
        Log::info("查询套餐总览");
        
        $setmealOverViewVO = $this->workspaceService->getSetmealOverView();
        return ResponseHelper::successJson($setmealOverViewVO->toArray());
    }
}